<?php

!defined('DEBUG') AND exit('Access Denied.');

$action = param(1);

if(!admin_authority_check()) header("Location:".url('index-login'));

if($action == 'list') {

	$pagesize = 10;
	$page = param('page', 1);
	$cid = param('cid', 0);
	$title = urldecode(param('title', 'all'));
	$cond = array();
	if($cid!=0) $cond['cid'] = $cid;
	if($title!='all') $cond['title'] = array('LIKE'=>'%'.$title.'%');
	$header['title'] = "文章列表";
	$catalog = db_find('article_catalog');
	$article = db_find('article', $cond, array('time'=>'-1'), $page, $pagesize);
	$count = db_count('article', $cond);
	$pagination = pagination(url("article-list").'?cid='.$cid.'&title='.$title.'&page={page}', $count, $page, $pagesize);
	include _include(ADMIN_PATH."view/htm/article_list.htm");

} elseif($action == 'update') {

	$aid = param(2, 0);
	if($method == 'GET') {
		$header['title'] = "文章编辑";
		$header['mobile_title'] = "文章编辑";
		$url = url('article-update-'.$aid);
		$article = db_find_one('article', array('id'=>$aid));
		$catalog = db_find('article_catalog');
		include _include(ADMIN_PATH."view/htm/article_update.htm");

	} elseif($method == 'POST') {
		$title = param('title');
		$content = param('content', '', false);
		$cid = param('cid');
		db_update('article', array('id'=>$aid), array('title'=>$title,'content'=>$content,'cid'=>$cid,'time'=>$time));
		message(0, "编辑成功");
	}

} elseif($action == 'add') {

	if($method == 'GET') {
		$header['title'] = "文章添加";
		$header['mobile_title'] = "文章添加";
		$url = url('article-add-'.$aid);
		$article = array('title'=>'','cid'=>0,'content'=>'');
		$catalog = db_find('article_catalog');
		include _include(ADMIN_PATH."view/htm/article_update.htm");

	} elseif($method == 'POST') {
		$title = param('title');
		$content = param('content', '', false);
		$cid = param('cid');
		db_insert('article', array('title'=>$title,'content'=>$content,'cid'=>$cid,'time'=>$time));
		message(0, "添加成功");
	}

} elseif ($action == 'delete') {
	if($method != 'POST') message(-1, 'Method Error.');
	$id = param('id', 0);
	$r = db_delete('article', array('id'=>$id));
	$r === FALSE AND message(-1, lang('delete_failed'));
	message(0, "删除成功");
}

?>